package com.worthtech.billportal.dao.hibernate;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.worthtech.billportal.bean.CsPosMerAccount;
import com.worthtech.billportal.bean.CsPosMerAccountLs;
import com.worthtech.billportal.dao.PosBindAccountDao;

public class PosBindAccountHibernateDao extends HibernateDaoSupport implements PosBindAccountDao {

	public void addAccount(CsPosMerAccount account) {
		this.getHibernateTemplate().save(account);
	}

	public String createLcHead(String LcHead) {
		return null;
	}

	public void delObj(CsPosMerAccountLs account) {
		this.getHibernateTemplate().delete(account);
	}

	@SuppressWarnings("unchecked")
	public List getByMerTrmcode(String tableName,
			String mercode, String trmcode,String sql) {
		List<CsPosMerAccountLs> list = this.getHibernateTemplate().find(
				"from "+tableName+" where POS_MER = '"+mercode+"' and POS_TERM = '"+trmcode+"' "+sql);
		if (list == null || list.isEmpty()) {
			return null;
		} else {
			return list;
		}
	}

	public String getCount(String tableName, String condition) {
		String hql = "select count(*) from " + tableName + " " + condition;
		System.out.println("hql1=" + hql);
		String tmp = this.getSession().createQuery(hql).list().get(0)
				.toString();
		System.out.println("count=" + tmp);
		return tmp;
	}

	@SuppressWarnings("unchecked")
	public List getListByHQL(String tableName, int startPage, int perNo,
			String orderby) {
		String hql = "from " + tableName + " " + orderby;
		System.out.println("hql2=" + hql);
		if (perNo == 0) {
			return this.getSession().createQuery(hql).list();
		}
		return this.getSession().createQuery(hql).setFirstResult(startPage)
				.setMaxResults(perNo).list();
	}

	public void updateFlag(CsPosMerAccount account) {
		this.getHibernateTemplate().update(account);
	}

	public void addAccountLS(CsPosMerAccountLs accountls) {
		this.getHibernateTemplate().save(accountls);
	}

	public void delObj(CsPosMerAccount account) {
		this.getHibernateTemplate().delete(account);
	}

	public void updateFlagLS(CsPosMerAccountLs account) {
		this.getHibernateTemplate().update(account);
	}


}
